/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Driver;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class DriverFetcher implements Fetcher<Driver>
{
    @Override
    public Driver fetch( ResultSet ps ) throws Exception
    {
        Driver d = new Driver();
        
        d.setId( ps.getInt( 1 ) );
        d.setPeopleId( ps.getInt( 2 ) );
        d.setCompanyId( ps.getInt( 3 ) );
        d.setCnh( ps.getString( 4 ) );
        d.setCnhDue( ps.getDate( 5 ) );
        d.setCnhCategory( ps.getString( 6 ) );
        d.setDefaultComission( ps.getDouble( 7 ) );
        d.setState( ps.getShort( 8 ) );
        
        return d;
    }

    @Override
    public void insert( Driver value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_drivers" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getPeopleId() );
        ps.setInt( 3, value.getCompanyId() );
        ps.setString( 4, value.getCnh() );
        ps.setDate( 5, value.getCnhDue() );
        ps.setString( 6, value.getCnhCategory() );
        ps.setDouble( 7, value.getDefaultComission() );
        ps.setShort( 8, value.getState() );
    }

    @Override
    public void update( Driver value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getPeopleId() );
        ps.setInt( 2, value.getCompanyId() );
        ps.setString( 3, value.getCnh() );
        ps.setDate( 4, value.getCnhDue() );
        ps.setString( 5, value.getCnhCategory() );
        ps.setDouble( 6, value.getDefaultComission() );
        ps.setShort( 7, value.getState() );
        ps.setInt( 8, value.getId() );
    }
    
}
